﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DiveManager
{
    public partial class ModulKeyMain : Form
    {
        protected DiveDatabaseEntities diveDatabase;
        protected BindingSource bindingSource;
        
        public ModulKeyMain()
        {
            InitializeComponent();

            // Init Database
            diveDatabase = new DiveDatabaseEntities();
            bindingSource = new BindingSource();
        }

        private void btDetails_Click(object sender, EventArgs e)
        {
            //Details zum ausgewählten Schlüssel anzeigen
        }

        private void btAdd_Click(object sender, EventArgs e)
        {
            //neuen Schlüssel erstellen
            ModulKeyAdd ModulKeyAdd = new ModulKeyAdd();
            ModulKeyAdd.ShowDialog();
        }

        protected void LoadData()
        {
            IQueryable<ModulKey_Main> dataQuery = (from a in diveDatabase.ModulKey_Main
                                                   select a);

            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;

            // Bind BindingSource to List
            KeyList.DataSource = bindingSource;


            // Hide ID-Columns
            KeyList.Columns["ID"].Visible = true;
            KeyList.Columns["Date"].Visible = false;
            KeyList.Columns["InUse"].Visible = true;
            KeyList.Columns["Status"].Visible = true;


            // Set Column Headers
            KeyList.Columns["ID"].HeaderText = "Schlüssel";
            KeyList.Columns["InUse"].HeaderText = "Benutzt";


        }

        private void ModulKeyMain_Load(object sender, EventArgs e)
        {
            LoadData();
        }
    }
}
